﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace DDOS.Objects.Effects
{
    class Explosion : GameObject
    {
        Rectangle spriteRectangle, sourceRectangle0, sourceRectangle1, sourceRectangle2;
        public bool deleteMe;
        private int time;
        public Entity source;

        public Explosion(Vector2 vect)
        {
            this.coordinates = vect;
            InitializeComponents();
        }


        public override void InitializeComponents()
        {
            time = 0;
            velocity = new Vector2(0,0);
            texture = ImageManager2D.Instance.Explosion;
            spriteRectangle = new Rectangle((int)coordinates.X, (int)coordinates.Y, (int)coordinates.X + 80, (int)coordinates.Y + 80);
            sourceRectangle0 = new Rectangle(0, 0, 80, 80);
            sourceRectangle1 = new Rectangle(80, 0, 160, 80);
            sourceRectangle2 = new Rectangle(160, 0, 240, 80);
        }

        public override void CollisionCallback(BoundingObject other, BoundingObject self)
        {
         /*   if (other.parent.GetType() == typeof(Enemy0))
            {
                ((Enemy0)other.parent).Health -= ((Projectile0)self.parent).damage;
                deleteMe = true;
            }
            if (other.parent.GetType() == typeof(Boss1))
            {
                ((Boss1)other.parent).Health -= ((Projectile0)self.parent).damage;
                deleteMe = true;
            }*/
        }

        public override void Update(GameTime game_time)
        {
            if (isActive)
            {
            boundingObject.Move(velocity.X, velocity.Y);
            spriteRectangle.X = (int)coordinates.X;
            spriteRectangle.Y = (int)coordinates.Y;
            time += 1;
            }
        }

        public override void Draw()
        {
            if (time <= 3)
            {
                   ScreenManager.Instance.CurrentSpriteBatch.Draw(texture, spriteRectangle, sourceRectangle0, Color.White);
            }
            if (time <= 6)
            {
                   ScreenManager.Instance.CurrentSpriteBatch.Draw(texture, spriteRectangle, sourceRectangle1, Color.White);
            }
            if (time <= 9)
            {
                   ScreenManager.Instance.CurrentSpriteBatch.Draw(texture, spriteRectangle, sourceRectangle2, Color.White);
            }
            if (time > 12)
            {   
                isActive = false;
            }
        }
    }
}

